package com.wdc.deliveryrobot.dialog;

import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wdc.deliveryrobot.R;

public class SelectDialog {

    public Dialog dialog;

    public LinearLayout imageButtonOne,imageButtonTwo,imageButtonThree,imageButtonFour;

    public ImageView imageOne,imageTwo,imageThree,imageFour;
    public TextView textViewOne,textViewTwo,textViewThree,textViewFour;

    public Button buttonCancel;

    public SelectDialog(Context context){
        dialog = new Dialog(context);
        dialog.setContentView(R.layout.dialog_select);
        dialog.setCancelable(false);

        imageButtonOne = dialog.findViewById(R.id.buttonOne);
        imageButtonTwo = dialog.findViewById(R.id.buttonTwo);
        imageButtonThree = dialog.findViewById(R.id.buttonThree);
        imageButtonFour = dialog.findViewById(R.id.buttonFour);

        imageOne = dialog.findViewById(R.id.imageOne);
        imageTwo = dialog.findViewById(R.id.imageTwo);
        imageThree = dialog.findViewById(R.id.imageThree);
        imageFour = dialog.findViewById(R.id.imageFour);

        textViewOne = dialog.findViewById(R.id.textOne);
        textViewTwo = dialog.findViewById(R.id.textTwo);
        textViewThree = dialog.findViewById(R.id.textThree);
        textViewFour = dialog.findViewById(R.id.textFour);

        buttonCancel = dialog.findViewById(R.id.cancel);

        // 设置 Dialog 的宽度和高度
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
        layoutParams.copyFrom(dialog.getWindow().getAttributes());
        layoutParams.width = 600; // 或设置为具体的像素值
        layoutParams.height = 350; // 或设置为具体的像素值
        // 设置 Dialog 的背景为圆角
        dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_white);
        dialog.getWindow().setAttributes(layoutParams);

        // 隐藏状态栏和导航栏
        if (dialog.getWindow() != null) {
            dialog.getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }


        buttonCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();

            }
        });
    }

    public void selectModel(String message) {
       //判断
        if (message.equals("配送")){
            imageOne.setImageResource(R.drawable.deliveryoneing);
        }else if (message.equals("回收")){
            imageTwo.setImageResource(R.drawable.recycloneing);
        }else if (message.equals("巡航")){
            imageThree.setImageResource(R.drawable.cruiseoneing);
        }else {
            imageFour.setImageResource(R.drawable.navigationoneing);
        }
    }

//    public void selectNoModel(String message) {
//        //判断
//        if (message.equals(textViewOne.getText().toString())){
//            imageButtonOne.setImageResource(R.drawable.deliveryone);
//        }else if (message.equals(textViewTwo.getText().toString())){
//            imageButtonOne.setImageResource(R.drawable.deliveryone);
//        }else if (message.equals(textViewThree.getText().toString())){
//            imageButtonOne.setImageResource(R.drawable.deliveryone);
//        }else {
//            imageButtonOne.setImageResource(R.drawable.deliveryone);
//        }
//    }

    public void setOneButtonClickListener(final View.OnClickListener listener) {
        imageButtonOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(v);
                }
                dialog.dismiss();

            }
        });
    }

    public void setTwoButtonClickListener(final View.OnClickListener listener) {
        imageButtonTwo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(v);
                }
                dialog.dismiss();

            }
        });
    }
    public void setThreeButtonClickListener(final View.OnClickListener listener) {
        imageButtonThree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(v);
                }
                dialog.dismiss();

            }
        });
    }
    public void setFourButtonClickListener(final View.OnClickListener listener) {
        imageButtonFour.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(v);
                }
                dialog.dismiss();

            }
        });
    }



    public void show() {
        dialog.show();
        if (dialog.getWindow() != null) {
            dialog.getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }

    public void dismiss() {
        dialog.dismiss();
    }
}
